/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012 Oliver Katz */

#ifndef __OPAL_EXTENDABILITY_H
#define __OPAL_EXTENDABILITY_H

#include <iostream>
#include <map>
#include "error.h"
#include "lexer.h"
#include "parser.h"

class ExtensionEnv
{
private:
	string name;
	AST self;
	AST parent;

public:
	ExtensionEnv();
	ExtensionEnv(string n, AST s, AST p);
	string getName();
	AST getSelf();
	AST getParent();
};

typedef AST (*ExtensionCallback)(ExtensionEnv);

class Extension
{
private:
	string name;
	ExtensionCallback callback;

public:
	Extension();
	Extension(string n, ExtensionCallback c);
	string getName();
	AST eval(AST self, AST parent);
};

class ExtensionManager
{
private:
	map<string, Extension> extensions;

public:
	ExtensionManager();
	int add(Extension e);
	Extension get(string n);
	AST extend(AST page, AST parent);
	AST extend(AST page);
};

#endif
